import java.util.ArrayList;
import java.util.List;
import java.util.Random;

public class CareGame {
    public static final String[] suits = {"♥","♠","♦","♣"};
    //生成一副扑克牌
    //52张 4种花色,每种花色13张
    public List<Card> buyCard() {//买牌 //将牌先分配花色
        List<Card> cardlist = new ArrayList<>();
        for (int i = 0; i < 4; i++) {
            for (int j = 0; j <= 13; j++) {
                String suit = suits[i];
                Card card = new Card(suit,j);
                cardlist.add(card);
                //cardlist.add(new Card(suits[i],j));
            }
        }
        return cardlist;
    }
    //洗牌
    public void shuffle(List<Card> cardList) {
        Random random = new Random();
        for (int i = cardList.size() -1; i>0; i--) {
            int index = random.nextInt(i);
            swap(cardList,i,index);
        }
    }
    public static void swap(List<Card> cardList,int i,int j) {//交换
        Card tmp = cardList.get(i);
        cardList.set(i,cardList.get(j));//set方法,把i下标赋j下标的值
        cardList.set(j,tmp);
    }
    //发牌 3个人 每个人轮流拿5张
    public List<List<Card>> getCard(List<Card> cardList) {
        //List是ArrayList的父类，都可用来实例化对象
        //实例化3个数组,用来 存放牌
        List<Card> hand1 = new ArrayList<>();
        ArrayList<Card> hand2 = new ArrayList<>();
        List<Card> hand3 = new ArrayList<>();
        //定义二维数组hand,用来存放三个人
        List<List<Card>> hand = new ArrayList<>();
        hand.add(hand1);
        hand.add(hand2);
        hand.add(hand3);
        //每人抓取10张牌
        for (int i = 0; i < 10; i++) {
            for (int j = 0; j < 3; j++) {
                Card card = cardList.remove(0);
                hand.get(j).add(card);
            }
        }
        return hand;
    }
}
